package com.android.camera2.common.utils;

import android.content.Context;
import android.media.AudioManager;
import android.media.MediaActionSound;
import android.media.MediaPlayer;
import android.net.Uri;
import com.android.camera2.common.sound.ISoundManager;

public class SoundManager implements ISoundManager {

    private Context mContext;
    private MediaActionSound mediaActionSound;
    public SoundManager(Context context){
        mContext = context;
        mediaActionSound = new MediaActionSound();
        mediaActionSound.load(MediaActionSound.SHUTTER_CLICK);
        mediaActionSound.load(MediaActionSound.START_VIDEO_RECORDING);
        mediaActionSound.load(MediaActionSound.STOP_VIDEO_RECORDING);
        mediaActionSound.load(MediaActionSound.FOCUS_COMPLETE);
    }

    @Override
    public void playShutterClickSound() {
        mediaActionSound.play(MediaActionSound.SHUTTER_CLICK);
    }

    @Override
    public void playDiySound() {
        AudioManager meng = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
        int volume = meng.getStreamVolume(AudioManager.STREAM_RING);
        MediaPlayer shootMP = null;
        if (volume != 0) {
            if (shootMP == null)
                //文件路径
                shootMP = MediaPlayer.create(mContext, Uri.parse("file:///system/media/audio/ui/camera_click.ogg"));
            if (shootMP != null)
                shootMP.start();
        }
    }

    @Override
    public void playRecordingSoundStart() {
        mediaActionSound.play(MediaActionSound.START_VIDEO_RECORDING);
    }

    @Override
    public void playRecordingSoundStop() {
        mediaActionSound.play(MediaActionSound.STOP_VIDEO_RECORDING);
    }
}
